package com.wuming.house.service.impl;

import com.wuming.house.core.BusinessException;
import com.wuming.house.dao.HouseImgMapper;
import com.wuming.house.model.HouseImg;
import com.wuming.house.service.HouseImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("houseImgService")
public class HouseImgServiceImpl extends BaseServiceImpl implements HouseImgService {

    @Autowired
    private HouseImgMapper houseImgMapper;

    @Override
    public void saveHouseImg(HouseImg hi) throws BusinessException {
        houseImgMapper.insert(hi);
    }

    @Override
    public List<HouseImg> getHouseImgByHouseId(Long houseId, Integer houseType, int pageIndex, int pageSize) throws BusinessException {
        Map<String, Object> params = new HashMap<>();
        params.put("houseId", houseId);
        if (null != houseType) {
            params.put("houseType", houseType);
        }
        try {
            return (List<HouseImg>) this.getPageList(HouseImgMapper.class, "selectByParams", params, pageIndex, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int getTotal(Long houseId, Integer houseType) throws BusinessException {
        Map<String, Object> params = new HashMap<>();
        params.put("houseId", houseId);
        if (null != houseType) {
            params.put("houseType", houseType);
        }
        try {
            return this.getTotal(HouseImgMapper.class, "selectTotal", params);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public void deleteById(Long id) throws BusinessException {
        houseImgMapper.deleteByPrimaryKey(id);
    }
}
